package com.jx.mlxg.common;

import com.jx.mlxg.common.BusinessException;
import com.jx.mlxg.common.ExceptionEnum;
import com.jx.mlxg.utils.ResponseResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public ResponseResult<?> handleBusinessException(BusinessException e) {
        return ResponseResult.failure(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseResult<?> handleException(Exception e) {
        e.printStackTrace();
        return ResponseResult.failure(ExceptionEnum.SYSTEM_ERROR.getCode(), ExceptionEnum.SYSTEM_ERROR.getMessage());
    }
}